<?php
/**
 * Created by PhpStorm.
 * User: zws
 * Date: 2018/9/8
 * Time: 11:02
 * 检测项目管理
 */
namespace app\index\service;

use app\common\model\ProjectModel;
use think\Exception;

class ProjectService
{
    protected static $projectModel;
    /**
     * UserService constructor.
     * @param ProjectModel $projectModel
     * @author zws
     */
    public function __construct(ProjectModel $projectModel)
    {
        self::$projectModel = $projectModel;
    }


    /**
     * 查询项目
     * @param $param
     * @return array
     * @author zws
     */
    public function index($param)
    {
        $result = self::$projectModel->where(['is_del'=>1])
            ->select();
        $resultArr = [];
        $data = [];
        if($result){
            $projectData = [];
            foreach ($result as $v)
            {
                if($v['pid'] == 0){
                    $data[] = $v;
                }else{
                    $projectData[$v['pid']][] = array(
                        'id'=>$v->id,
                        'project_name'=>$v->project_name,
                    );
                }
            }
            foreach ($data as $k=>$v){
                $resultArr[$k] = array(
                    'id'=>$v->id,
                    'project_name'=>$v->project_name,
                );
                $resultArr[$k]['projectData'] = [];
                if(isset($projectData[$v['id']]))
                {
                    $resultArr[$k]['projectData'] = $projectData[$v['id']];
                }
            }
        }
        return $resultArr;
    }


}